package com.turbo.cloud.core.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.function.Supplier;

/**
 * List2List浅拷贝
 * @author zhangluning
 */
public class BeanListUtils extends BeanUtils {

    /**
     * 转换对象
     *
     * @param sources        源对象list
     * @param targets        源对象list
     * @param targetSupplier 目标对象供应方
     * @param <S>            源对象类型
     * @param <T>            目标对象类型
     * @return 目标对象list
     */
    public static <S, T> void copyList(List<S> sources, List<T> targets, Supplier<T> targetSupplier) {
        if (null == sources || null == targets || null == targetSupplier) {
            return;
        }

        for (S source : sources) {
            T target = targetSupplier.get();
            copyProperties(source, target);
            targets.add(target);
        }
    }
}
